/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var resultTable = $("resultTable");
var req;
var addButton;

function addFriend(form) {
    var url = "AddFriend?targetId=" + escape(form.targetId.value);
    addButton = form.add;
    req = initRequest();
    req.open("GET", url, true);
    req.onreadystatechange = addFriend_callback;
    req.send(null);
}

function addFriend_callback() {
    if (req.readyState == 4 && req.status == 200) {
        addFriend_parseMessage(req.responseXML);
    }
}

function addFriend_parseMessage(responseXML) {
    if (responseXML == null) {
        //
    } else {
        var message = responseXML.getElementsByTagName("message")[0];
        var toPrint = message.childNodes[0].nodeValue;
        if (toPrint.toString() == "Your request was sent") {
            addButton.value = "Sent request";
            addButton.disabled = "disabled";
            var numOfWaitings = parseInt($("numOfWaitings").innerHTML);
            $("numOfWaitings").innerHTML = numOfWaitings + 1;
        } else {
            alert(message.childNodes[0].nodeValue);
        }
    }
}



